//算法调整，按照数组每列对应的下标值相加，获取纵坐标最大值
export function calMax(arr) {
    let max = 0;
    let summerArr = []
    for (let key in arr) {
        arr[key].map((val, index) => {
            if (!summerArr[index]) {
                summerArr[index] = 0
            }
            summerArr[index] += Number(val);
        });
    }
    max = Math.max(...summerArr);
    let maxint = Math.ceil(max / 10);//不让最高的值超过最上面的刻度
    let maxval = maxint * 10//让刻度显示整数
    return maxval;
}
//计算最小值
export function calMin(arr) {
    let min = 0;
    arr.forEach((arr1) => {
        arr1.forEach((el) => {
            if (!(el === undefined || el === "")) {
                if (min > el) {
                    min = el;
                }
            }
        });
    });
    let minint = Math.floor(min / 10);
    let minval = minint * 10
    return minval
}
export function chartExcel(opt, persentName = '', unitType = null) {
    let axisData = opt.xAxis[0].axisData
    let series = opt.series
    let tdHeads = '<td style="padding:0 10px"></td>'
    let tdBodys = ""
    series.forEach((item) => {
        tdHeads += `<td style="padding:0 10px">${item.name}</td>`
    })
    let table = `<table border='1' style="margin-left:20px;border-collapse:collapse;font-size:14px;text-align:center;user-select:auto"><tbody><tr>${tdHeads}</tr>`
    for (let i = 0, l = axisData.length; i < l; i++) {
        for (let j = 0; j < series.length; j++) {
            if (persentName == series[j].name) {
                if (unitType == 'onePersent') {
                    tdBodys += `<td>1:${series[j].data[i]}</td>`
                } else {
                    tdBodys += `<td>${series[j].data[i]}%</td>`
                }
            } else {
                tdBodys += `<td>${series[j].data[i]}</td>`
            }
        }
        table += `<tr><td style="padding:0 10px>${axisData[i]}</td>${tdBodys} </tr>`
        tdBodys = ''
    }
    table += "</tbody></table>"
    return table
}